﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Cookies : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.Cookies["LastVisit"] != null)
        {

            Label1.Text = Server.HtmlEncode(Request.Cookies["LastVisit"].Value.ToString());

        }

        if (Request.Cookies["lastVisit"] != null)
        {
            HttpCookie cookies4 = Request.Cookies["LastVisit"];
            Label2.Text = Server.HtmlEncode(cookies4.Value);

        }

        if (Request.Cookies["UserData"] != null) 
        {
            Label3.Text = Server.HtmlEncode(Request.Cookies["UserData"]["LastVisit"].ToString());
            System.Collections.Specialized.NameValueCollection cookiescollection = Request.Cookies["UserData"].Values;
            Label4.Text = Server.HtmlEncode(cookiescollection["LastVisit"].ToString());


        }

        

        //Method 1 
        Response.Cookies["LastVisit"].Value = DateTime.Now.ToString();
        Response.Cookies["LastVisit"].Expires = DateTime.Now.AddDays(1);


        //Method 2
        HttpCookie Cookie = new HttpCookie("LastVisit");
        Cookie.Value = DateTime.Now.ToString();
        Cookie.Expires = DateTime.Now.AddDays(2);
        Response.Cookies.Add(Cookie);


        Response.Cookies["UserId"].Value = "10";
        Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(1);
        Response.Cookies["UserData"]["LastVisit"] = DateTime.Now.ToString();
        Response.Cookies["UserData"]["UserId"] = "10";

        HttpCookie cookie1 = new HttpCookie("UserData");
        cookie1.Values["LastVisit"] = DateTime.Now.ToString();
        cookie1.Values["UserId"] = "10";
        cookie1.Expires = DateTime.Now.AddDays(1);
        Response.Cookies.Add(cookie1);

        HttpCookie cookie2 = new HttpCookie("UserData");
        cookie2.Values["LastVisit"] = DateTime.Now.ToString();
        cookie2.Values["UserId"] = "10";
        cookie2.Expires = DateTime.Now.AddDays(1);
        cookie2.Path = "/Admin";
        Response.Cookies.Add(cookie2);

        HttpCookie cookie3 = new HttpCookie("UserData");
        cookie3.Values["LastVisit"] = DateTime.Now.ToString();
        cookie3.Values["UserId"] = "10";
        cookie3.Expires = DateTime.Now.AddDays(1);
        cookie3.Domain = "supportmysite.com";
        Response.Cookies.Add(cookie3);

       
        Response.Cookies["LastVisit"].Value = DateTime.Now.ToString();
        Response.Cookies["LastVisit"].Expires = DateTime.Now.AddDays(1);


        Response.Cookies["LastVisit"].Expires = DateTime.Now.AddDays(-1);
    }


   protected void BtnSubmit_Click(object sender, EventArgs e)
    {
            string Url;
            Url = "DisplayValue.aspx?ViewId=1";
            Response.Cookies["FName"].Value= TxtFName.Text;
            Response.Cookies["LName"].Value= TxtLName.Text;
            Response.Cookies["Email"].Value = TxtEmail.Text;
            Response.Cookies["Dob"] .Value= TxtDob.Text;
            Response.Redirect(Url);
       
   }

    
}
